﻿using System;
using System.Collections.Generic;
using System.Text;
using CadStrategy2013.DxfData;
using MyIni;

namespace CadStrategy2013.CgqStyle
{
    public class YpFsClass : Cgq2013
    {
        public YpFsClass(string secname)
            : base(secname)
        {
        }
        public YpFsClass(string secname, Dictionary<string, string> dic)
            :base(secname,dic)
        {
        }
        //public override void GetCfg()
        //{
        //    base.GetCfg();
        //    GetCfg("无绝缘发送");
        //}
        public override List<string> ReadTemplateDxf()
        {
            return ReadDxf(Path + "\\template\\无绝缘发送.dll");
        }
        public override string GetSaveFileName(int index)
        {
            if (ShiJiTuZhiCount == 1)
                return "\\无绝缘发送.dxf";
            return "\\无绝缘发送" + (index + 1).ToString() + ".dxf";

        }
        private DxfDataClass GetUmlDxfData(DxfDataClass dxfDataClass, IniFile inifile)
        {
            int sum0 = inifile.GetInt16("um71", "sum", 0);
            string[] strGCDingXing1 = inifile.GetString("um71", "功出定型1", "").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string[] strGCDingXing2 = inifile.GetString("um71", "功出定型2", "").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string[] strGRDingXing1 = inifile.GetString("um71", "轨入定型1", "").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string[] strGRDingXing2 = inifile.GetString("um71", "轨入定型2", "").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string[] strFsDlDingXing = inifile.GetString("um71", "发送电流定型", "").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < sum0; i++)
            {
                DevClass devClass = new DevClass();
                string strs = inifile.GetString("um71", (i + 1).ToString(), "");
                string[] s = strs.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                int n = s.Length;
                devClass.DevName = s[0];
                try
                {
                    if (s[2] == "2")
                    {
                        devClass.peiList.Add(s[1] + strGCDingXing2[0]);
                        devClass.peiList.Add(s[1] + strGCDingXing2[1]);
                    }
                    else
                    {
                        devClass.peiList.Add(s[1] + strGCDingXing1[0]);
                        devClass.peiList.Add(s[1] + strGCDingXing1[1]);
                    }
                    devClass.peiList.Add(s[4]);
                    devClass.peiList.Add(s[5]);
                    devClass.cpeiList.Add(s[3] + strFsDlDingXing[0]);
                    devClass.cpeiList.Add(strFsDlDingXing[1]);
                    devClass.cpeiList.Add(s[6]);
                    devClass.cpeiList.Add(s[8]);
                }
                catch 
                {
                    devClass.peiList.Clear();
                    devClass.cpeiList.Clear();
                    for (int i1 = 0; i1 < 4; i1++)
                    {
                        devClass.peiList.Add("");
                        devClass.cpeiList.Add("");
                    }
                }
                dxfDataClass.devList.Add(devClass);
            }
            if (sum0 != 0)
            {
                ShiJiBanCount = (dxfDataClass.devList.Count - 1) / BanDevCount + 1;
                ShiJiTuZhiCount = (ShiJiBanCount - 1) / BanCount + 1;
            }
            //else
            //{
            //    ShiJiBanCount = 0;
            //    ShiJiTuZhiCount = 0;
            //}
            m_dxfDataClass = dxfDataClass;
            return dxfDataClass;
        }
        private DxfDataClass Get2000DxfData(DxfDataClass dxfDataClass, IniFile inifile)
        {
            int sum0 = inifile.GetInt16("2000", "sum", 0);
            string[] strGCDingXing = inifile.GetString("2000", "功出定型", "").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string[] strFsDlDingXing = inifile.GetString("2000", "发送电流定型", "").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string[] strDlcDlDingXing = inifile.GetString("2000", "电缆侧电流", "").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < sum0; i++)
            {
                DevClass devClass = new DevClass();
                string strs = inifile.GetString("2000", (i + 1).ToString(), "");
                string[] s = strs.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                // int n = s.Length;
                devClass.DevName = s[0];
                try
                {

                    devClass.peiList.Add(s[1] + strGCDingXing[0]);
                    devClass.peiList.Add(s[1] + strGCDingXing[1]);
                    if (s[0].Contains("+"))
                    {
                        devClass.peiList.Add("");
                        devClass.peiList.Add("");
                        devClass.cpeiList.Add("");
                        devClass.cpeiList.Add("");
                        devClass.cpeiList.Add("");
                        devClass.cpeiList.Add("");
                    }
                    else
                    {
                        devClass.peiList.Add(s[3] + "-" + s[4]);
                        devClass.peiList.Add(s[3] + "-" + s[5]);
                        devClass.cpeiList.Add(s[2] + strFsDlDingXing[0]);
                        devClass.cpeiList.Add(strFsDlDingXing[1]);
                        devClass.cpeiList.Add(strDlcDlDingXing[0]);
                        devClass.cpeiList.Add(s[3] + "-" + s[4]);
                    }
                }
                catch 
                {
                    devClass.peiList.Clear();
                    devClass.cpeiList.Clear();
                    for (int i1 = 0; i1 < 4; i1++)
                    {
                        devClass.peiList.Add("");
                        devClass.cpeiList.Add("");
                    }
                }
                dxfDataClass.devList.Add(devClass);
            }
            if (sum0 != 0)
            {
                ShiJiBanCount = (dxfDataClass.devList.Count - 1) / BanDevCount + 1;
                ShiJiTuZhiCount = (ShiJiBanCount - 1) / BanCount + 1;
            }
            //else
            //{
            //    ShiJiBanCount = 0;
            //    ShiJiTuZhiCount = 0;
            //}
            m_dxfDataClass = dxfDataClass;
            return dxfDataClass;
        }
        public override DxfDataClass GetDxfData()
        {
            DxfDataClass dxfDataClass = new DxfDataClass();
            IniFile inifile = new IniFile("./\\" + StationName + "\\yp.txt");
            DxfDataClass dxfdata = GetUmlDxfData(dxfDataClass, inifile);
            dxfdata = Get2000DxfData(dxfdata, inifile);
            return dxfdata;
        }
        //public override string ReplaceCPei(string str, int fi = 0)
        //{
        //    for (int j = 1; j <= BanCount; j++)
        //    {
        //        int nj = j - fi * BanCount;
        //        for (int i = 1; i <= 8; i++)
        //        {
        //            string str1 = "cpei" + nj.ToString() + "-" + i.ToString() + ">";
        //            if (str.Contains(str1))
        //            {
        //                int index = (j - 1) * BanDevCount + (i - 1) / 4;
        //                if (index >= m_dxfDataClass.devList.Count)
        //                    return "";
        //                int index1 = (i - 1) % 4;
        //                try
        //                {
        //                    // if (m_dxfDataClass.devList[index].cpeiList.Count > 1)
        //                    return str = str.Replace(str1, m_dxfDataClass.devList[index].cpeiList[index1]);
        //                }
        //                catch (Exception e)
        //                {
        //                    return "";
        //                }
        //            }
        //        }
        //    }
        //    return str;
        //}
        //public override string ReplacePei(string str, int fi = 0)
        //{
        //    if (fi == 1)
        //    {
        //    }
        //    for (int j = 1; j <= BanCount; j++)
        //    {
        //        int nj = j;// -fi * BanCount;
        //        for (int i = 1; i <= 2 * BanDevPeiCount * BanDevCount; i++)
        //        {
        //            string str1 = "pei" + nj.ToString() + "-" + i.ToString() + ">";
        //            if (str.Contains(str1))
        //            {
        //               // int index = (j - 1) * BanDevCount + (i - 1) / BanDevPeiCount;
        //                int index = (fi * BanCount + (j - 1)) * BanDevCount;
        //                if (index >= m_dxfDataClass.devList.Count)
        //                    return "";
        //                int index1 = (i - 1) % 4;
        //                try
        //                {
        //                    return str = str.Replace(str1, m_dxfDataClass.devList[index].peiList[index1]);
        //                }
        //                catch (Exception e)
        //                {
        //                    return "";
        //                }
        //            }
        //        }
        //    }
        //    return str;
        //}
    }
}
